package cn.com.sinosoft.dbyb.mr.function;

import com.google.common.base.Joiner;
import lombok.Getter;
import lombok.Setter;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * ClassName: CusBean
 * Description: 自定义的Bean
 * Date: 2018/4/4 9:46 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Setter
@Getter
public class CusBean implements WritableComparable<CusBean> {

    private static final Joiner JOINER = Joiner.on("|");

    /**
     * 个人编号
     */
    private String aac999;

    /**
     * 交易流水号
     */
    private String ckc016;

    /**
     * 医疗结算事件id
     */
    private String cka009;
    /**
     * 自负金额
     */
    private String akc254;
    /**
     * 累计自负费用
     */
    private String sumAkc254;
    /**
     * 本次自负赔付
     */
    private String akc254Compensate = "0";

    /**
     * 累计自负赔付
     */
    private String sumAkc254Compensate= "0";

    /**
     * 合规自费金额(取小后的本次合规自费费用)
     */
    private String complianceOwnExpense;
    /**
     * 累计合规费用
     */
    private String sumComplianceOwnExpense;

    /**
     * 自负+合规自费
     */
    private String akc254AddComplianceOwnExpense;

    /**
     * 累计自负费用+累计合规费用
     */
    private String sumAkc254AddComplianceOwnExpense= "0";

    /**
     * 本次自负加合规赔付(COE = Compliance Own Expense)
     */
    private String akc254AddCOECompensate= "0";

    /**
     * 累计自负加合规赔付
     */
    private String sumAkc254AddCOECompensate= "0";

    /**
     * 本次合计赔付
     */
    private String sumPayMoney= "0";

    /**
     * 结算日期
     */
    private String cke011;

    /**
     * 交易日期（排序依据）
     */
    private String bke032;


    /**
     * 当前日期时间
     */
    private String today;


    /**
     * 救助转换标识
     * 2-救助转普通（上次是救助、本次是普通），需要特殊处理；
     * 1-救助（其他都是普通）
     */
    private String sFlag;

    /**
     * 区分本期数据与往期数据（MR自己设计使用）
     * 1-本期 0-往期
     */
    private int flag;

    @Override
    public int compareTo(CusBean o) {
        int compare = this.aac999.compareToIgnoreCase(o.getAac999());
        return compare == 0 ? (bke032.compareTo(o.getBke032()) == 0 ? cka009.compareTo(o.getCka009()) : bke032.compareTo(o.getBke032())) : compare;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(this.aac999);
        out.writeUTF(this.ckc016);
        out.writeUTF(this.cka009);
        out.writeUTF(this.akc254);
        out.writeUTF(this.sumAkc254);

        out.writeUTF(this.akc254Compensate);
        out.writeUTF(this.sumAkc254Compensate);
        out.writeUTF(this.complianceOwnExpense);
        out.writeUTF(this.sumComplianceOwnExpense);
        out.writeUTF(this.akc254AddComplianceOwnExpense);

        out.writeUTF(this.sumAkc254AddComplianceOwnExpense);
        out.writeUTF(this.akc254AddCOECompensate);
        out.writeUTF(this.sumAkc254AddCOECompensate);
        out.writeUTF(this.sumPayMoney);
        out.writeUTF(this.cke011);

        out.writeUTF(this.bke032);
        out.writeUTF(this.sFlag);
        out.writeInt(this.flag);

    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.aac999 = in.readUTF();
        this.ckc016 = in.readUTF();
        this.cka009 = in.readUTF();
        this.akc254 = in.readUTF();
        this.sumAkc254 = in.readUTF();

        this.akc254Compensate = in.readUTF();
        this.sumAkc254Compensate = in.readUTF();
        this.complianceOwnExpense = in.readUTF();
        this.sumComplianceOwnExpense = in.readUTF();
        this.akc254AddComplianceOwnExpense = in.readUTF();

        this.sumAkc254AddComplianceOwnExpense = in.readUTF();
        this.akc254AddCOECompensate = in.readUTF();
        this.sumAkc254AddCOECompensate = in.readUTF();
        this.sumPayMoney = in.readUTF();
        this.cke011 = in.readUTF();

        this.bke032 = in.readUTF();
        this.sFlag = in.readUTF();
        this.flag = in.readInt();
    }

    @Override
    public String toString() {
        return JOINER.join(
                aac999,
                ckc016,
                cka009,
                akc254,
                sumAkc254,

                akc254Compensate,
                sumAkc254Compensate,
                complianceOwnExpense,
                sumComplianceOwnExpense,
                akc254AddComplianceOwnExpense,

                sumAkc254AddComplianceOwnExpense,
                akc254AddCOECompensate,
                sumAkc254AddCOECompensate,
                sumPayMoney,
                cke011,
                bke032,
                today
        );

    }

    /**
     * 加载本次数据
     *
     * @param arr
     */
    public void loadDate(String[] arr) {

        this.aac999 = arr[0];
        this.cka009 = arr[1];
        this.akc254 = arr[2];
        this.sumAkc254 = arr[3];
        this.complianceOwnExpense = arr[4];

        this.sumComplianceOwnExpense = arr[5];
        this.akc254AddComplianceOwnExpense = arr[6];
        this.sumAkc254AddComplianceOwnExpense = arr[7];
        this.bke032 = arr[8];
        this.ckc016 = arr[9];

        this.cke011 = arr[10];
        this.sFlag = arr[11];
    }

    /**
     * 加载往期数据
     * 往期数据其中使用到的为：
     * sumAkc254（累计自负）、sumComplianceOwnExpense（累计合规费用）、sumAkc254AddComplianceOwnExpense（累计自负+合规）、
     * sumAkc254Compensate（累计自负赔付）、sumAkc254AddCOECompensate（累计自负加合规赔付）
     *
     * @param arr
     */
    public void loadOldDate(String[] arr) {
        this.aac999 = arr[0];
        this.ckc016 = arr[1];
        this.cka009 = arr[2];
        this.akc254 = arr[3];
        this.sumAkc254 = arr[4];

        this.akc254Compensate = arr[5];
        this.sumAkc254Compensate = arr[6];
        this.complianceOwnExpense = arr[7];
        this.sumComplianceOwnExpense = arr[8];
        this.akc254AddComplianceOwnExpense = arr[9];

        this.sumAkc254AddComplianceOwnExpense = arr[10];
        this.akc254AddCOECompensate = arr[11];
        this.sumAkc254AddCOECompensate = arr[12];

        this.cke011 = arr[14];
        this.bke032 = arr[15];
    }

    public void copyProperties(CusBean target) {

        target.setAac999(this.getAac999());
        target.setCkc016(this.getCkc016());
        target.setCka009(this.getCka009());
        target.setAkc254(this.getAkc254());
        target.setSumAkc254(this.getSumAkc254());

        target.setAkc254Compensate(this.getAkc254Compensate());
        target.setSumAkc254Compensate(this.getSumAkc254Compensate());
        target.setComplianceOwnExpense(this.getComplianceOwnExpense());
        target.setSumComplianceOwnExpense(this.getSumComplianceOwnExpense());
        target.setAkc254AddComplianceOwnExpense(this.getAkc254AddComplianceOwnExpense());

        target.setSumAkc254AddComplianceOwnExpense(this.getSumAkc254AddComplianceOwnExpense());
        target.setAkc254AddCOECompensate(this.getAkc254AddCOECompensate());
        target.setSumAkc254AddCOECompensate(this.getSumAkc254AddCOECompensate());
        target.setCke011(this.getCke011());
        target.setBke032(this.getBke032());

        target.setSumPayMoney(this.getSumPayMoney());
        target.setSFlag(this.getSFlag());
        target.setFlag(this.getFlag());
    }


}
